#ifndef __MUL32_H__
#define __MUL32_H__

/** 
 * \brief 32x32=32 multilpication
 *
 * Use the following algorithm\n
 * <tt>
 * a = (H1<<16 + L1)\n
 * b = (H2<<16 + L2)\n
 * c = (H1<<16 + L1) * (H2<<16 + L2) >> 16\n
 * </tt>
 *
 * \param[in] a
 * \param[in] b
 *
 * \return 32-bit result
 *
 * \ingroup Control
 */
static __inline L1_INT32 mul32(L1_INT32 a, L1_INT32 b)
{
    L1_UINT16 L1 = (L1_UINT16)a;
    L1_INT16  H1 = (L1_INT16)(a >> 16);
    L1_UINT16 L2 = (L1_UINT16)b;
    L1_INT16  H2 = (L1_INT16)(b >> 16);

    L1_INT32 c = H1*H2 + (H1*L2 >> 16) + (L1*H2 >> 16);

    return c;
}

#endif // __MUL32_H__
